package com.example.bookstore.entity

import com.fasterxml.jackson.annotation.JsonView
import javax.persistence.*

/**
 * Created by IntelliJ IDEA.
 * User: lvshe
 * Date: 2019/8/8
 * Time: 15:46
 */
@Table
@Entity
class BookCategoryEntity : BaseEntity {

    constructor() : super()
    constructor(name: String, order: Int) : super() {
        this.name = name
        this.order = order
    }


    @JsonView(BookCategoryView::class)
    @Column(nullable = false)
    var name = ""

    @JsonView(BookCategoryView::class)
    @Column(nullable = false, name = "bc_order")
    var order: Int = 0

    @ManyToMany
    @JsonView(BookCategoryViewWithBook::class)
//    @Fetch(FetchMode.JOIN)
    @JoinTable(name = "book_categories")
//    @JsonIgnoreProperties("categories")
    var books: Set<BookEntity> = hashSetOf()

    interface BookCategoryView : BaseWithIdView
    interface BookCategoryViewWithBook : BookCategoryView
    interface BookCategoryViewWithBookWithCategory : BookCategoryViewWithBook, BookEntity.BookWithCategory
}